﻿using System;
using System.Data;
using System.Collections;
using System.Text.RegularExpressions;
using System.Text;
using System.Web.Caching;

using LTJ.Common;
using LTJ.Data;
using LTJ.Config;
using LTJ.Entity;
using LTJ.Common.Generic;
using LTJ.Cache;

namespace LTJ.FrameWork
{
    /// <summary>
    /// 航线基本信息操作
    /// </summary>
    public class RouteBases
    {
        /// <summary>
        /// 创建航线信息
        /// </summary>
        /// <param name="rbinfo"></param>
        /// <returns></returns>
        public static int CreateRouteBase(RouteBaseInfo rbinfo)
        {
            return Data.DataProvider.RouteBases.CreateRouteBase(rbinfo);
        }
        /// <summary>
        /// 批量删除操作
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public static int DelRouteBase(string ids)
        {
            return Data.DataProvider.RouteBases.DelRouteBase(ids);
        }

        /// <summary>
        /// 航线基本信息分页操作（DataTable对象)
        /// </summary>
        public static DataTable GetRouteBaseTableByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return Data.DataProvider.RouteBases.GetRouteBaseTableByPage(pageindex, pagesize, condition, ordercolumn == "" ? "id" : ordercolumn, ordertype == "" ? "desc" : ordertype);
        }

        /// <summary>
        /// 航线基本信息分页操作(table)
        /// </summary>
        public static DataTable GetRouteBaseSearchTableByPage(int type, int oid, int cid, int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return Data.DataProvider.RouteBases.GetRouteBaseSearchTableByPage(type, oid, cid, pageindex, pagesize, condition, ordercolumn == "" ? "id" : ordercolumn, ordertype == "" ? "desc" : ordertype);
        }

        /// <summary>
        /// 航线基本信息分页操作
        /// </summary>
        public static List<RouteBaseInfo> GetRouteBaseListByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return Data.DataProvider.RouteBases.GetRouteBaseListByPage(pageindex, pagesize, condition, ordercolumn == "" ? "id" : ordercolumn, ordertype == "" ? "desc" : ordertype);
        }

        /// <summary>
        /// 搜索航线基本信息分页操作
        /// </summary>
        public static List<RouteBaseInfo> GetRouteBaseSearchByPage(int type, int oid, int cid, int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return Data.DataProvider.RouteBases.GetRouteBaseSearchByPage(type, oid, cid, pageindex, pagesize, condition, ordercolumn == "" ? "id" : ordercolumn, ordertype == "" ? "desc" : ordertype);
        }

        /// <summary>
        /// 航线数量
        /// </summary>
        public static int GetRouteBasesCount(string conditions)
        {
            return Data.DataProvider.RouteBases.GetRouteBasesCount(conditions);
        }
        /// <summary>
        /// 搜索航线数量
        /// </summary>
        public static int GetRouteBaseListCount(int type, int oid, string conditions)
        {
            return Data.DataProvider.RouteBases.GetRouteBaseListCount(type, oid, conditions);
        }

        /// <summary>
        /// 修改航线信息
        /// </summary>
        public static int UpdateRouteBase(RouteBaseInfo rbinfo)
        {
            return Data.DataProvider.RouteBases.UpdateRouteBase(rbinfo);
        }

        /// <summary>
        /// 快捷价格修改
        /// </summary>
        /// <param name="rid">线路ID</param>
        /// <param name="price1">20GP</param>
        /// <param name="price2">40GP</param>
        /// <param name="price3">40HQ</param>
        public static int UpdateRouteBasePrice(int rid, string price1, string price2, string price3)
        {
            return Data.DataProvider.RouteBases.UpdateRouteBasePrice(rid, price1, price2, price3);
        }

        /// <summary>
        /// 获取航线实体信息
        /// </summary>
        public static RouteBaseInfo GetRouteBaseInfo(int id)
        {
            RouteBaseInfo rinfo = Data.DataProvider.RouteBases.GetRouteBaseInfo(id);
            return rinfo;
        }
        /// <summary>
        /// 获取搜索航线实体信息
        /// </summary>
        public static RouteBaseInfo GetSearchRouteBaseInfo(int id, int type, int oid, int cid)
        {
            return Data.DataProvider.RouteBases.GetSearchRouteBaseInfo(id, type, oid, cid);
        }
        
        public static int UpdateRouteBaseStatus(string ids, int val)
        {
            return Data.DataProvider.RouteBases.UpdateRouteBaseStatus(ids, val);
        }
        
        /// <summary>
        /// 航线列表搜索条件生成
        /// </summary>
        /// <param name="cid">所属公司ID</param>
        /// <param name="isuse">是否启用（-1为不限，0为未启用，1，为启用中）</param>
        /// <param name="loadport">起运港口</param>
        /// <param name="objectport">目的港口</param>
        /// <param name="routeline">航线</param>
        /// <param name="corp">船公司</param>
        public static string GetRouteBaseCondation(int cid, int isuse, string loadport, string objectport, string routeline, string corp)
        {
            return Data.DataProvider.RouteBases.GetRouteBaseCondation(cid, isuse, loadport, objectport, routeline, corp);
        }

        /// <summary>
        /// 返回航线价格
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="tcode">类型</param>
        /// <param name="dcode">数据</param>
        /// <param name="pcode">规格</param>
        /// <param name="pricestr"></param>
        /// <returns></returns>
        public static string ReturnRoutePrice(DataTable dt, string tcode, string dcode, string pcode, string pricestr)
        {
            string rprice = "0";
            if (dt == null) return "0";
            foreach (DataRow dr in dt.Select(" tcode='" + tcode + "' and dcode='" + dcode + "' and pcode='" + pcode + "'"))
            {
                rprice = dr[pricestr].ToString();
            }

            return rprice;
        }

        /// <summary>
        /// 批量修改线路价格信息
        /// </summary>
        public static int UpdateBatchRoutePrice(RouteBaseInfo rinfo, string ids)
        {
            return Data.DataProvider.RouteBases.UpdateBatchRoutePrice(rinfo, ids);
        }

        /// <summary>
        /// 批量修改线路基本信息
        /// </summary>
        public static int UpdateBatchRouteInfo(RouteBaseInfo rinfo, string ids)
        {
            return Data.DataProvider.RouteBases.UpdateBatchRouteInfo(rinfo, ids);
        }
    }
}
